package com.wangce.util;

import com.wangce.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ClassName: MyInterceptor
 * Description:
 * date: 2021/11/14 18:27
 *
 * @author 凡人
 * @since JDK 1.8
 */
public class MyInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        User user = (User) request.getSession().getAttribute("user");
        if(user==null){
            response.sendRedirect("login");
            return false;
        }
        return true;
    }
}
